/**
 * @file   1055.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Mon Jul 26 23:08:33 2021
 * 
 * @brief  PAT advanced 1055
 * 
 * 
 */
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
class people{
public:
    string name;
    int age;
    int wealth;
};
bool cmp(people& P1,people& P2){
    if(P1.wealth>P2.wealth){
	return true;
    }else if(P1.wealth==P2.wealth){
	if(P1.age<P2.age){
	    return true;
	}
	else if(P1.age==P2.age){
	    if(P1.name<P2.name){
		return true;
	    }
	}
    }
    return false;
}
class Solution{
private:
    vector<people> board;
    int peoplenum;
    int requirenum;
public:
    Solution();
    void require(int maxnum,int minage,int maxage);
    void solve();
};
Solution::Solution(){
    cin>>peoplenum>>requirenum;
    for(int i=0;i<peoplenum;i++){
	people P;
	cin>>P.name>>P.age>>P.wealth;
	board.push_back(P);
    }
    sort(board.begin(),board.end(),cmp);
}
void Solution::solve(){
    for(int i=0;i<requirenum;i++){
	int maxnum,minage,maxage;
	cin>>maxnum>>minage>>maxage;
	cout<<"Case #"<<(i+1)<<":"<<endl;
	require(maxnum,minage,maxage);
    }
}
void Solution::require(int maxnum,int minage,int maxage){
    int okay=0;//the number of "okay" people!
    for(int i=0;i<board.size();i++){
	if(okay>=maxnum){//complete the result!
	    return;
	}
	if(board[i].age>=minage&&board[i].age<=maxage){
	    okay++;
	    cout<<board[i].name<<" "<<board[i].age<<" "<<board[i].wealth<<endl;
	}
    }
    if(okay==0){
	cout<<"None"<<endl;
    }
    return;
}
int main(){
    Solution S;
    S.solve();
}
